#ifndef _JT_H_
#define _JT_H_

#include "list.h"
#include "metaSet.h"

struct _cdn
{
	uint32 a;
	uint32 b;
};
typedef struct _cdn cdn;

DEF_LIST_WITH_TYPE(cdn, uint32, uint32);

DEF_LIST_FUNCTIONS(cdn, uint32, uint32);


typedef struct testInfo
{
	char hopsIp[128];
	uint32 offsetTime;
	cdn_list cdnHead;
	cdn* abb;
}testInfo;

DECLARE_MATE_BEGIN(cdn)
	PARAMETER(cdn, a, STB_DATA_UINT32, 0, 0),
	PARAMETER(cdn, b, STB_DATA_UINT32, 0, 0),
DECLARE_MATE_END()

/*
META metaCdn[] = {
	PARAMETER(cdn, a, STB_DATA_UINT32, 0, 0),
	PARAMETER(cdn, b, STB_DATA_UINT32, 0, 0),
	
	{0, 0, 0, 0, 0}
};
*/

DECLARE_MATE_BEGIN(testInfo)
	PARAMETER(testInfo, hopsIp, STB_DATA_STR, 0, 0),
	PARAMETER(testInfo, cdnHead, JSON_DATA_LIST, meta_cdn, 0),
	PARAMETER(testInfo, offsetTime, STB_DATA_UINT32, 0, 0),
	PARAMETER(testInfo, abb, JSON_DATA_PTR, meta_cdn, "googo"),
DECLARE_MATE_END()

/*
META metaTestInfo[] = {
	PARAMETER(testInfo, hopsIp, STB_DATA_STR, 0, 0),
	PARAMETER(testInfo, cdnHead, JSON_DATA_LIST, metaCdn, 0),
	PARAMETER(testInfo, offsetTime, STB_DATA_UINT32, 0, 0),
	PARAMETER(testInfo, abb, JSON_DATA_PTR, metaCdn, "googo"),
	
	{0, 0, 0, 0, 0}
};
*/

/* another solution for struct serialize.
char* cdnToJson(cdn* cdnData, char* name)
{
	if(cdnData == NULL)
		return NULL;

	char* str = NULL;
	str = serialize(cdnData->a, STB_DATA_UINT32, "a");
	json_string_append(str, str, str);
	str = serialize(cdnData->b, STB_DATA_UINT32, "b");
	json_string_append(str, str, str);
	return 0;
}

char* testInfoToJson(testInfo* data, char* name);
{
	if(data == NULL)
		return NULL;

	char* str = NULL;
	str = serialize(data->hopsIp, STB_DATA_UINT32, "hopsIp");
	json_string_append(str, str, str);
	
	str = serialize(data->offsetTime, STB_DATA_UINT32, "offsetTime");
	json_string_append(str, str, str);
	
	str = cndToJson(data->abb, "abb");
	json_string_append(str, str, str);
	json_string_append(str, str, ",");

	list_node_cdn* node = get_first_cdn_node(&data->cdnHead);
	json_string_append(str, str, ",[");
	while(node != NULL)
		{
		cndToJson(node->data, "a");
		json_string_append(str, str, str);

		node = get_next_cdn_node(node);
		}
	json_string_append(str, str, "]");
	return 0;
}
*/

#endif /* _JT_H_ */

